package com.vcs.frm.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.joda.MillisecondInstantPrinter;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;


public class DailyMailScheduler {

	@Autowired
	private JavaMailSender mailSender;
	
	public void setMailSender(JavaMailSender mailSender) {
		this.mailSender = mailSender;
	}
	
	/**
	 * fixedDelay = 86400000 for daily
	 * every 5 mins = 1000 * 60 * 5
	 */
	@Scheduled(fixedDelay = 86400000)
	public void sendDailyMails(){
		
		SimpleMailMessage msg = new SimpleMailMessage();
		msg.setFrom("myjob.vcs@gmail.com");
		msg.setTo("myjob.vcs@gmail.com");
		msg.setSubject("This is a scheduled email from the Spring School project");
		msg.setText("this is email body");
		
		mailSender.send(msg);
		System.out.println("Sending daily mails...... ");
	}
	
}
